/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */
package cn.hermit.data.json.model;

import cn.hermit.util.OSUtils;

import java.io.Serializable;

/**
 * Abstract class of JSON objects. It's a parent class of all JSON objects.
 * <p>
 * Any JSON objects such like JSON Object, JSON Array, JSON Value can be treated 
 * as a common JSON Document.
 * </p>
 * 
 * @author Jack Gao (Chinese name : GAO JIANGUO, Email : linux.gjg@gmail.com)
 * @date 13 Jun, 2014
 */
public abstract class JSONDocument implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4817607957575089678L;

	JSONDocument parent;

	JSONDocument() {

	}

	public String toFormatString() {
		return toFormatString(0, true);
	}

	/**
	 * Format JSON string with tab indents.
	 * 
	 * @param depth
	 * 		number of tab indents
	 * @return
	 * 		Formatted JSON string
	 */
	public String toFormatString(int depth) {
		return toFormatString(depth, true);
	}

	String toFormatString(int depth, boolean isTop) {
		return toFormatString(depth, OSUtils.NEW_LINE_FEED_DEFAULT, isTop);
	}

	/**
	 * Format JSON string with tab indents.
	 * 
	 * @param depth
	 * 		Number of tab indents
	 * @param newLineFeed
	 * 		New line break
	 * @return
	 * 		Formatted JSON string
	 */
	public String toFormatString(int depth, String newLineFeed) {
		return toFormatString(depth, newLineFeed, true);
	}

	abstract String toFormatString(int depth, String newLineFeed, boolean isTop);

	/**
	 * @return the parent of JSON object
	 */
	public JSONDocument getParent() {
		return parent;
	}
	
	/**
	 * Check if the object is JSON Array
	 * @return	
	 */
	public abstract boolean isArray();
	
	/**
	 * Check if the object is JSON Object
	 * @return
	 */
	public abstract boolean isObject();
	
	/**
	 * Check if the object is JSON Value
	 * @return
	 */
	public abstract boolean isValue();
	
	/**
	 * Check if the JSON Value is string type
	 * @return
	 */
	public abstract boolean isTextValue();
	
}